package com.suypower.carManage.action;

import javax.servlet.ServletException;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

public class SecureAction extends ActionSupport {

    private String id;
    private String car_code;
    private String insurer;    //承保公司
    private String insurance_jq_stime;    //交强险开始时间
    private String insurance_jq_etime;    //交强险结束时间
    private String insurance_jq_warranty;    //交强险保单号
    private String insurance_jq_premium;     //交强险保费
    private String vesselusetax;            //车船使用税
    private String insurance_commercial_stime;    //商业保险开始时间
    private String insurance_commercial_etime;    //商业保险结束时间
    private String premium;    //商业保险费
    private String policy;    //保单号

    public String getInsurer() {
        return insurer;
    }

    public void setInsurer(String insurer) {
        this.insurer = insurer;
    }

    public String getInsurance_jq_stime() {
        return insurance_jq_stime;
    }

    public void setInsurance_jq_stime(String insurance_jq_stime) {
        this.insurance_jq_stime = insurance_jq_stime;
    }

    public String getInsurance_jq_etime() {
        return insurance_jq_etime;
    }

    public void setInsurance_jq_etime(String insurance_jq_etime) {
        this.insurance_jq_etime = insurance_jq_etime;
    }

    public String getInsurance_jq_warranty() {
        return insurance_jq_warranty;
    }

    public void setInsurance_jq_warranty(String insurance_jq_warranty) {
        this.insurance_jq_warranty = insurance_jq_warranty;
    }

    public String getInsurance_jq_premium() {
        return insurance_jq_premium;
    }

    public void setInsurance_jq_premium(String insurance_jq_premium) {
        if (insurance_jq_premium == null || insurance_jq_premium.equals("")) {
            this.insurance_jq_premium = null;
        } else {
            this.insurance_jq_premium = insurance_jq_premium;
        }
    }

    public String getVesselusetax() {
        return vesselusetax;
    }

    public void setVesselusetax(String vesselusetax) {
        if (vesselusetax == null || vesselusetax.equals("")) {
            this.vesselusetax = null;
        } else {
            this.vesselusetax = vesselusetax;
        }
    }

    public String getInsurance_commercial_stime() {
        return insurance_commercial_stime;
    }

    public void setInsurance_commercial_stime(String insurance_commercial_stime) {
        this.insurance_commercial_stime = insurance_commercial_stime;
    }

    public String getInsurance_commercial_etime() {
        return insurance_commercial_etime;
    }

    public void setInsurance_commercial_etime(String insurance_commercial_etime) {
        this.insurance_commercial_etime = insurance_commercial_etime;
    }

    public String getPremium() {
        return premium;
    }

    public void setPremium(String premium) {
        this.premium = premium;
    }

    public String getPolicy() {
        return policy;
    }

    public void setPolicy(String policy) {
        this.policy = policy;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCar_code() {
        return car_code;
    }

    public void setCar_code(String carCode) {
        car_code = carCode;
    }

    public String execute() {
        String res = "";
        DAO dao = new DAO();
        String sql = "";
        
        if (premium == null || premium.trim().equals("")) {
            this.premium = null;
        }

        if (vesselusetax == null || vesselusetax.trim().equals("")) {
            this.vesselusetax = null;
        }

        if (insurance_jq_premium == null || insurance_jq_premium.trim().equals("")) {
            this.insurance_jq_premium = null;
        }

        if (id != null && !id.equals("")) {
            sql = "UPDATE dbo.tb_secure SET car_code = '" + car_code + "', insurer = '" + insurer + "', insurance_jq_stime = '" + insurance_jq_stime + "', insurance_jq_etime = '" + insurance_jq_etime + "', insurance_jq_warranty = '" + insurance_jq_warranty + "', insurance_jq_premium = " + insurance_jq_premium + ", vesselusetax = " + vesselusetax + ", insurance_commercial_stime = '" + insurance_commercial_stime + "', insurance_commercial_etime = '" + insurance_commercial_etime + "', premium = " + premium + ", policy = '" + policy + "' where id=" + id;
        } else {
            sql = "INSERT INTO dbo.tb_secure ( car_code, insurer, insurance_jq_stime, insurance_jq_etime, insurance_jq_warranty, insurance_jq_premium, vesselusetax, insurance_commercial_stime, insurance_commercial_etime, premium, policy ) VALUES ( '" + car_code + "', '" + insurer + "', '" + insurance_jq_stime + "', '" + insurance_jq_etime + "', '" + insurance_jq_warranty + "', " + insurance_jq_premium + ", " + vesselusetax + ", '" + insurance_commercial_stime + "', '" + insurance_commercial_etime + "', " + premium + ", '" + policy + "' )";
        }

        int count = 0;
        try {
            count = dao.execCommand(ConstUtil.DBNAME, sql);
            if (count > 0) {
                res = this.SUCCESS;
            } else {
                res = this.ERROR;
            }
        } catch (ServletException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return res;
    }
}
